package com.example.kotlinstudy.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import com.example.demo01.R


/**
 * A simple [Fragment] subclass.
 * Use the [DetailFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class DetailFragment : Fragment() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_detail, container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<TextView>(R.id.title).text = "闷闷哒"
        view.findViewById<TextView>(R.id.title)
            .setBackgroundColor(resources.getColor(R.color.teal_700))

        // 找到返回按钮并设置点击事件监听器
        view.findViewById<Button>(R.id.back_button).setOnClickListener {
            // 点击返回按钮时弹出Fragment回退栈，实现返回列表功能
            parentFragmentManager.popBackStack()
        }

    }

}